package com.ubxtech.db.generator;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import jakarta.validation.constraints.NotNull;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @author Victor.Xiao
 * @since 2023-08-18 14:23
 **/
public class CustomVelocityTemplateEngine  extends VelocityTemplateEngine {

    @Override
    protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
        String entityName = tableInfo.getEntityName();
//        String parentPath = getPathInfo(OutputFile.parent);
        //数据库表映射实体名称 驼峰命名法
        objectMap.put("humpEntityName",toLowerCaseFirstOne(entityName));
        super.outputCustomFile(customFiles, tableInfo, objectMap);
    }


    /**
     * 首字母转为小写
     */
    private  String toLowerCaseFirstOne(String s){
        if(Character.isLowerCase(s.charAt(0))) {
            return s;
        }else {
            return Character.toLowerCase(s.charAt(0)) + s.substring(1);
        }
    }
}
